function checkUserInfo(cb) {
  var that = this;

  wx.getSetting({
    success(res) {
      if (!res.authSetting['scope.userInfo']) {
        typeof cb == 'function' && cb(false);
      } else {
        wx.getUserInfo({
          success: function (res) {
            console.log('成功获取用户信息')
            wx.setStorage({
              key: 'userInfo',
              data: res.userInfo,
              success: function (res) {
                console.log('userInfo写入缓存成功', res)
              }
            })
          },
          fail: function (res) {
            console.log('wx.getUserInfo 接口调用失败，将无法获取用户信息', res)
          }
        })
        typeof cb == "function" && cb(true)
      }
    },
    fail(err) {
      typeof cb == "function" && cb(false)
    }
  })
}

//检查用户录音授权 已经授权返回true 未授权会提示用户授权并返回授权结果
function checkRecord(cb) {
  var that = this
  wx.getSetting({
    success: (res) => {
      console.log('授权列表信息', res)
      if (!res.authSetting['scope.record']) {
        wx.authorize({
          scope: 'scope.record',
          success: (res) => {
            typeof cb == "function" && cb(true)
          },
          fail: () => {
            typeof cb == 'function' && cb(false);
          }
        })
      } else {
        typeof cb == "function" && cb(true)
      }
    },
    fail: function (res) {
      typeof cb == "function" && cb(false)
    }
  })
}

module.exports = {
  checkUserInfo,
  checkRecord
}